package cc.opcol.iot.server.util;

import java.util.concurrent.*;

public class ThreadUtil {
    BlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(10);
    RejectedExecutionHandler handler = new ThreadPoolExecutor.CallerRunsPolicy();
    ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(128, 128, 0, TimeUnit.SECONDS, queue, handler);

    static ThreadUtil threadUtil;

    public static ThreadUtil getInstance(){
        if(threadUtil==null){
            threadUtil=new ThreadUtil();
        }
        return threadUtil;
    }

    public void execute(Runnable runnable) {
        poolExecutor.execute(runnable);
    }
}
